<?php
require_once 'modules/product/models/ProductCategory.php';
require_once 'modules/content/models/ContentCategory.php';
class main_menuSticker extends Nine_Sticker
{
	public function run()
	{
		$langCode = Nine_Registry::get('langCode');
		
		/**
		 * Get all product category
		 */
		$objCat = new Models_ContentCategory();
		$objCat = new Models_ContentCategory();
		$objProCat = new Models_ProductCategory();
		$vnToursCats = $objProCat->getAllProductCatWithParent(61,2);
		$toursCats = $objProCat->getAllProductCatWithParent(63,2);
		$hotelCats = $objProCat->getAllProductCatWithParent(65,2);
		$newsCats = $objCat->getAllContentCatWithParent(7,2);
		
		$newsMenus = array(
                    'url' => Nine_Route::_("content/index/index/cid/7",array('alias' => 'tin-tuc')),
                    'name' => Nine_Language::translate('NEWS'),
                    'id' => 'news',
            		'childs' => array()
                    );
         $hotelMenus = array(
                    'url' => Nine_Route::_("product/index/index/cid/65",array('alias' => 'hotel')),
                    'name' => Nine_Language::translate('HOTEL'),
                    'id' => 'product_category_65',
                    'childs' => array()
                    );
         $toursMenus = array(
                    'url' => Nine_Route::_("product/index/index/cid/63",array('alias' => 'dich-vu')),
                    'name' => Nine_Language::translate('TOUR SERVICE'),
                    'id' => 'product_category_63'
                    );
          $vnToursMenus = array(
                    'url' => Nine_Route::_("product/index/index/cid/61",array('alias' => 'du-lich')),
                    'name' => Nine_Language::translate('VIET NAM DAILY TOURS'),
                    'id' => 'product_category_61'
                    );
                    
		 foreach($newsCats as $newsCat) {
				$tmp = array();
				$tmp['url'] = Nine_Route::_("content/index/index/cid/{$newsCat['content_category_gid']}",array('alias' => $newsCat['alias']));
				$tmp['name'] = $newsCat['name'];
				$tmp['id'] = $newsCat['content_category_gid'];
				$tmp['childs'] = array();
				if (!empty($newsCat['child'])) {
					foreach ($newsCat['child'] as $item) {
						$tmp2 = array();
						$tmp2['url'] = Nine_Route::_("content/index/index/cid/{$item['content_category_gid']}",array('alias' => $item['alias']));
						$tmp2['name'] = $item['name'];
						$tmp2['id'] = $item['content_category_gid'];
						$tmp2['childs'] = array();
						
						$tmp['childs'][] = $tmp2;
					}
				}
				
				$newsMenus['childs'][] = $tmp;
			}
			
		foreach($hotelCats as $hotelCat) {
				$tmp = array();
				$tmp['url'] = Nine_Route::_("product/index/index/cid/{$hotelCat['product_category_gid']}",array('alias' => $hotelCat['alias']));
				$tmp['name'] = $hotelCat['name'];
				$tmp['id'] = $hotelCat['product_category_gid'];
				$tmp['childs'] = array();
				if (!empty($hotelCat['child'])) {
					foreach ($hotelCat['child'] as $item) {
						$tmp2 = array();
						$tmp2['url'] = Nine_Route::_("product/index/index/cid/{$item['product_category_gid']}",array('alias' => $item['alias']));
						$tmp2['name'] = $item['name'];
						$tmp2['id'] = $item['product_category_gid'];
						$tmp2['childs'] = array();
						
						$tmp['childs'][] = $tmp2;
					}
				}
				
				$hotelMenus['childs'][] = $tmp;
			}
			
		foreach($toursCats as $toursCat) {
					$tmp = array();
					$tmp['url'] = Nine_Route::_("product/index/index/cid/{$toursCat['product_category_gid']}",array('alias' => $toursCat['alias']));
					$tmp['name'] = $toursCat['name'];
					$tmp['id'] = $toursCat['product_category_gid'];
					$tmp['childs'] = array();
					if (!empty($toursCat['child'])) {
						foreach ($toursCat['child'] as $item) {
							$tmp2 = array();
							$tmp2['url'] = Nine_Route::_("product/index/index/cid/{$item['product_category_gid']}",array('alias' => $item['alias']));
							$tmp2['name'] = $item['name'];
							$tmp2['id'] = $item['product_category_gid'];
							$tmp2['childs'] = array();
							
							$tmp['childs'][] = $tmp2;
						}
					}
					
				$toursMenus['childs'][] = $tmp;
			}
		foreach($vnToursCats as $vnToursCat) {
						$tmp = array();
						$tmp['url'] = Nine_Route::_("product/index/index/cid/{$vnToursCat['product_category_gid']}",array('alias' => $vnToursCat['alias']));
						$tmp['name'] = $vnToursCat['name'];
						$tmp['id'] = $vnToursCat['product_category_gid'];
						$tmp['childs'] = array();
						if (!empty($vnToursCat['child'])) {
							foreach ($vnToursCat['child'] as $item) {
								$tmp2 = array();
								$tmp2['url'] = Nine_Route::_("product/index/index/cid/{$item['product_category_gid']}",array('alias' => $item['alias']));
								$tmp2['name'] = $item['name'];
								$tmp2['id'] = $item['product_category_gid'];
								$tmp2['childs'] = array();
								
								$tmp['childs'][] = $tmp2;
							}
						}
						
				$vnToursMenus['childs'][] = $tmp;
			}
			
			
			
	 
			
			
		$menus = array(
            0 => array(
                    'url' => Nine_Registry::getBaseUrl(),
                    'name' => Nine_Language::translate('HOME'),
                    'id' => 'home'
                    ),
            
            1 => $vnToursMenus,
            2 => $hotelMenus,
                  
           	3 => $toursMenus,
            4 => $newsMenus,
            
            5 => array(
                    'url' => Nine_Route::_(Nine_Registry::getBaseUrl()."contact-us.html"),
                    'name' => Nine_Language::translate('CONTACT'),
                    'id' => 'contactus'
                    ),
        );
        
//        echo "<pre>";print_r($menus);die;

        
        $this->view->menus = $menus;
        /**
         * random number
         */
        $this->view->randomNumber = rand(0, 1000000);
	}
}